from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess, SetEnvironmentVariable
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution
from launch_ros.actions import Node

def generate_launch_description():

    # Declare the 'type' argument with default value 'normal'
    type_arg = DeclareLaunchArgument(
        "type",
        default_value="modbus",
        description='type [normal, modbus, hmodbus, can, hcan]'
    )

    # Create a Node action to start the imu node
    imu_node = Node(
        package='wit_ros',
        executable=['wit_', LaunchConfiguration('type'), '_ros'],
        name='imu',
        output='screen',
        parameters=[{"port":'/dev/ttyUSB0',"baud":115200}]
    )

    # Create a Node action to start the rviz node
    rviz_node = Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=['-d', './src/wit_ros/rviz/wit_ros_imu.rviz']
    )

    # Create the LaunchDescription and add the actions
    ld = LaunchDescription()

    # Add the arguments to the launch description
    ld.add_action(type_arg)

    # Add the nodes to the launch description
    ld.add_action(imu_node)
    ld.add_action(rviz_node)

    return ld
